var index = 0;

module.exports = {
  'GET /signin': async (ctx, next) => {
    let names = '甲乙丙丁戊己庚辛壬癸';
    let name = names[index % 10];
    console.log(name)
    ctx.render('signin.html', {
      name: `路人${name}`
    });
  },
  'POST /signin': async (ctx, next) => {
    index ++;
    let name = JSON.parse(ctx.request.body).userName || '路人甲';
    let user = {
      id: index,
      name: name,
      image: index % 10
    };
    ctx.state.user = user;
    let value = Buffer.from(JSON.stringify(user)).toString('base64');
    ctx.cookies.set('name', value);
    ctx.response.body = {
      status: 200,
      data: {
        user,
        cookie: value
      }
    };
    // ctx.response.redirect('/');
  },
  'GET /signout': async (ctx, next) => {
    ctx.cookies.set('name', '');
    ctx.response.redirect('/signin');
  }
}